<template>
  <view class="container">
    <view class="header">
      <text class="title">任务审批系统</text>
      <u-button 
        class="share-btn" 
        @click="openShareModal"
        type="primary"
        shape="circle"
        size="mini"
      >
        <u-icon name="share" size="24"></u-icon>
      </u-button>
    </view>
    
    <view class="content">
      <view class="task-card">
        <view class="task-title">项目进度报告</view>
        <view class="task-info">
          <view class="info-item">
            <text class="info-label">提交人：</text>
            <text class="info-value">张三</text>
          </view>
          <view class="info-item">
            <text class="info-label">提交时间：</text>
            <text class="info-value">2023-07-21 14:30</text>
          </view>
          <view class="info-item">
            <text class="info-label">状态：</text>
            <text class="info-value status-pending">待审批</text>
          </view>
        </view>
        <view class="task-content">
          <text>本月项目进度已完成80%，各项主要完成了以下工作：</text>
          <view class="task-list">
            <view class="task-item">• 需求分析与设计</view>
            <view class="task-item">• 核心功能开发</view>
            <view class="task-item">• 单元测试</view>
          </view>
          <text>下一步计划：</text>
          <view class="task-list">
            <view class="task-item">• 系统集成测试</view>
            <view class="task-item">• 用户验收测试</view>
            <view class="task-item">• 系统部署部署</view>
          </view>
        </view>
      </view>
      
      <view class="action-buttons">
        <u-button 
          class="action-btn reject-btn"
          type="error"
        >
          拒绝
        </u-button>
        <u-button 
          class="action-btn approve-btn"
          type="primary"
        >
          同意
        </u-button>
      </view>
    </view>
    
    <!-- 分享弹窗 -->
    <share-modal 
      ref="shareModal"
      :share-config="shareConfig"
      @close="onShareClose"
      @result="onShareResult"
    ></share-modal>
  </view>
</template>

<script>
import ShareModal from './components/share-modal/share-modal.vue';
import { isWeComEnv } from '@/utils/wecom-api.js';
import { showToast } from '@/utils/toast.js';

export default {
  name: 'Index',
  components: {
    ShareModal
  },
  data() {
    return {
      // 分享配置
      shareConfig: {
        title: '项目进度报告',
        content: '本月项目进度已完成80%，请查阅详情',
        logo: '/static/logo.png',
        userName: uni.getStorageSync('userName'),
        date: new Date().toLocaleDateString(),
		// backgroundImage: '/static/homeNav/kmh.png', // 背景图地址
        bgColor: '#ffffff',
        shareUrl: window.location.href // H5环境下的分享链接
      }
    };
  },
  onLoad() {
    // 检查当前环境
    console.log('是否在企业微信环境:', isWeComEnv());
    console.log('当前URL:', window.location.href);
  },
  methods: {
    /**
     * 打开分享弹窗
     */
    openShareModal() {
      this.$refs.shareModal.open();
    },
    
    /**
     * 分享弹窗关闭回调
     */
    onShareClose() {
      console.log('分享弹窗已关闭');
    },
    
    /**
     * 分享结果回调
     */
    onShareResult(result) {
      console.log('分享结果:', result);
      
      // 在H5环境下，除了分享弹窗的提示外，再显示一个toast提示
      if (!isWeComEnv()) {
        showToast(result.success ? '操作成功' : '操作失败', result.success ? 'success' : 'error');
      }
    }
  }
};
</script>

<style lang="scss" scoped>
.container {
  min-height: 100vh;
  background-color: #f5f7fa;
  padding: 30rpx;
}

.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 30rpx;
  
  .title {
    font-size: 36rpx;
    font-weight: bold;
    color: #333;
  }
  
  .share-btn {
    width: 60rpx;
    height: 60rpx;
    display: flex;
    justify-content: center;
    align-items: center;
    background-color: #0057b8;
  }
}

.content {
  display: flex;
  flex-direction: column;
  gap: 30rpx;
}

.task-card {
  background-color: #fff;
  border-radius: 16rpx;
  padding: 30rpx;
  box-shadow: 0 4rpx 20rpx rgba(0, 0, 0, 0.05);
  
  .task-title {
    font-size: 32rpx;
    font-weight: bold;
    color: #333;
    margin-bottom: 20rpx;
    padding-bottom: 20rpx;
    border-bottom: 1px solid #eee;
  }
  
  .task-info {
    margin-bottom: 20rpx;
    
    .info-item {
      display: flex;
      margin-bottom: 15rpx;
      
      .info-label {
        font-size: 26rpx;
        color: #666;
        width: 160rpx;
      }
      
      .info-value {
        font-size: 26rpx;
        color: #333;
        flex: 1;
      }
      
      .status-pending {
        color: #ff9500;
      }
    }
  }
  
  .task-content {
    font-size: 26rpx;
    color: #333;
    line-height: 1.6;
    
    .task-list {
      margin: 15rpx 0;
      padding-left: 30rpx;
      
      .task-item {
        margin-bottom: 10rpx;
      }
    }
  }
}

.action-buttons {
  display: flex;
  justify-content: space-between;
  
  .action-btn {
    width: 48%;
    height: 90rpx;
    font-size: 30rpx;
    border-radius: 16rpx;
  }
  
  .reject-btn {
    background-color: #fff;
    color: #ff3b30;
    border: 1px solid #ff3b30;
  }
  
  .approve-btn {
    background-color: #0057b8;
    color: #fff;
  }
}
</style>
